Repository navigation
Conversation
The multiprocess path saves each picture through tempfile.mkdtemp(prefix=
"docx_img_"), then recognises its own files with a literal POSIX prefix
("/tmp/docx_img_") in _process_batch_results and again in
_cleanup_temp_image_files. On Windows mkdtemp returns
C://Users//...//Temp//docx_img_xxxx, so the predicate is False for every
image the parser just wrote: nothing is collected and every multimodal
docx parse leaves its PNGs and their directories behind.
Decide from the directory name instead, which is identical on every
platform, and keep one predicate for both call sites.
Author
|
Closing as a duplicate of #5795, which carries the same fix for the same function (and the same test file) from the previous day. Sorry for the noise. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Observed
The multiprocess path saves each picture with
tempfile.mkdtemp(prefix="docx_img_")and then recognises its own files by a literal POSIX prefix. On Windowsmkdtempreturns a path under%TEMP%, so that predicate isFalsefor every image the parser just wrote:Nothing is collected, so
_cleanup_temp_image_filesis called with an empty set and returns at its firstif not temp_paths. Every multimodal.docxparse leaves one directory plus one PNG per image in the temp directory, on Windows only.Expected
The images the parser wrote for its workers are removed when the batch finishes, on every platform.
Root cause
docreader/parser/docx_parser.py, two hard-coded"/tmp/docx_img_"checks:_process_batch_resultscollectsimage_data.local_pathonly when it starts with that prefix;_cleanup_temp_image_filesremoves the per-image directory only when the directory starts with it.tempfile.mkdtempputs the directory wherevergettempdir()points, so the prefix only ever matches on hosts whose temp directory happens to be/tmp.Fix
Add one predicate — the parent directory's name starts with
docx_img_, which is whatmkdtemp(prefix=...)guarantees — and use it at both call sites. Path separators no longer matter, and the POSIX behaviour is unchanged because those paths satisfy the new predicate too.Reproduction and verification
Windows 11 / Python 3.13.
Before, on
main, with the real path the function returns (_save_image_to_tempprobe above): the old rule rejects it, so the file is never collected.After:
test_an_image_saved_for_a_worker_is_collected_and_removedsaves a real image through_save_image_to_temp, asserts the path is collected, runs_cleanup_temp_image_filesand asserts both the PNG and its directory are gone.test_a_path_outside_the_image_temp_dirs_is_not_collectedkeeps the predicate from over-reaching.Affected surface (docx parsing suites):